package com.rongshu.view.home.presenter;

import android.content.Context;

import com.rongshu.api.RetorfitService;
import com.rongshu.utils.Common;
import com.rongshu.utils.UserInfoUtils;
import com.rongshu.view.base.mvp.BasePresenter;
import com.rongshu.view.base.mvp.INetView;
import com.rongshu.view.home.entity.DaySignListResponse;
import com.rongshu.view.home.entity.MakeDaySignBody;

import java.util.HashMap;
import java.util.Map;

import rx.Subscriber;

/**
 * created by zhengweis on 2019/2/22.
 * description：
 */
public class DaySignListPresenter extends BasePresenter<INetView> {

    public DaySignListPresenter(Context context) {
        super(context);
    }

    public void getDaySignList(final int type, int pageIndex, int pageSize, String date) {
        Map<String, Object> map = new HashMap<>();
        map.put("user_id", UserInfoUtils.getUserId());
        map.put("type", type);
        map.put("pageIndex", pageIndex);
        map.put("pageSize", pageSize);
        MakeDaySignBody body = new MakeDaySignBody();
        body.setDailyDate(date);
        body.setImgUrl("");
        body.setImgExplain("");
        body.setDailyContent("");
        RetorfitService.getDaySignList(UserInfoUtils.getUserId(), type, pageIndex, pageSize, Common.encryptionSign(map), body)
                .compose(getView().<DaySignListResponse>bindToLife())
                .subscribe(new Subscriber<DaySignListResponse>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(DaySignListResponse info) {
                        if (info.getErrCode() == 0) {
                            getView().success(info, type);
                        }
                    }
                });
    }
}
